package com.example.demo.config;

import com.example.demo.api.GameAPI;
import com.example.demo.api.MatchApI;
import com.example.demo.api.TestApI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;


@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private TestApI testApI;

    @Autowired
    private MatchApI matchApI;

    @Autowired
    private GameAPI gameAPI;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(testApI,"/test");   //注册效果
        registry.addHandler(matchApI,"/findMatch").
                addInterceptors(new HttpSessionHandshakeInterceptor());   //这一步是将Http的session搞到我们webSocket中的session中
        registry.addHandler(gameAPI,"/game").addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
